#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 3e2 + 10, INF = 0x3f3f3f3f;

int n, k;
string s;
int f[N][N];

void solve()
{
    cin >> s >> k; n = s.length();
    s = " " + s;
    for (int i = 1;i <= n;i++) f[i][i] = 1;

    for (int len = 2;len <= n;len++)
        for (int l = 1;l + len - 1 <= n;l++) {
            int r = l + len - 1;
            f[l][r] = f[l + 1][r] + 1;
            if (s[l] != 'o') continue;
            for (int x = l + 1;x <= r;x++)
                if (s[x] == 'f' && f[l + 1][x - 1] == 0)
                    f[l][r] = min(f[l][r], max(f[x + 1][r] - k, 0));
        }
    cout << f[1][n] << '\n';
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}